<template>
  <div class="goods-list">
    <!-- <h3>列表</h3> -->
    <!-- <router-link tag="div" class="goods-item" v-for="item in list" 
    :key="item.data" :to="'/home/goodsinfo/'+item.id">
      <img :src="item.src">
      <h1 class="title">{{item.name}}</h1>
      <div class="info">
        <p class="price">
          <span class="now">￥{{item.now}}</span>
          <span class="old">￥{{item.old}}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>剩余{{item.have}}台</span>
        </p>
      </div>
    </router-link>-->

    <!-- 编程式导航 -->
    <div class="goods-item" v-for="item in list" :key="item.data">
      <img :src="item.src" @click="gotoDetail(item.id)">
      <h1 class="title">{{item.name}}</h1>
      <div class="info">
        <p class="price">
          <span class="now">￥{{item.now}}</span>
          <span class="old">￥{{item.old}}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>剩余{{item.have}}台</span>
        </p>
      </div>
    </div>
    <mt-button type="danger" size="large" @click="getMore" plain>加载更多</mt-button>
  </div>
</template>

<script>
import "../../../aaa_lianxi/mock_goods_list";
export default {
  data() {
    return {
      list: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.$http.get("/home/goodslist").then(res => {
        // console.log(res);
        this.list = this.list.concat(res.body.goods);
      });
    },
    getMore() {
      this.getList();
    },
    gotoDetail(id) {
    //   this.$router.push("/home/goodsinfo/" + id);
    // this.$router.push({path:'/home/goodsinfo/'+id})
      this.$router.push({name:'goodsinfo',params:{id}})
    }
  }
};
</script>

<style lang="scss" scoped>
.goods-list {
  display: flex;
  flex-wrap: wrap;
  padding: 7px;
  justify-content: space-between;

  .goods-item {
    width: 49%;
    border: 1px solid #ccc;
    box-shadow: 0 0 8px #ccc;
    margin: 4px 0;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    max-height: 300px;
    img {
      width: 100%;
    }
    .title {
      font-size: 14px;
    }
    .info {
      background-color: #eee;
      margin: 0px;
      padding: 5px;
      .price {
        .now {
          color: red;
          font-size: 16px;
          font-weight: bold;
        }
        .old {
          text-decoration: line-through;
          font-size: 12px;
          margin-left: 10px;
        }
      }
      .sell {
        display: flex;
        justify-content: space-between;
        font-size: 13px;
      }
    }
  }
}
</style>
